package god530.com.simpleapp_slide;

import android.os.Bundle;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import god530.com.simpleapp_slide.account.fragment.AccountFragment;
import god530.com.simpleapp_slide.account.menu.feedback.FeedBackActivity;
import god530.com.simpleapp_slide.account.menu.gesture.GestureActivity;
import god530.com.simpleapp_slide.account.menu.help.HelpActivity;
import god530.com.simpleapp_slide.account.menu.order.OrderActivity;
import god530.com.simpleapp_slide.account.menu.setting.SettingActivity;
import god530.com.simpleapp_slide.account.menu.user.UserActivity;
import god530.com.simpleapp_slide.account.tabs.account.AccountActivity;
import god530.com.simpleapp_slide.account.tabs.details.DetailsActivity;
import god530.com.simpleapp_slide.account.tabs.report.ReportActivity;
import god530.com.simpleapp_slide.account.tabs.write.WriteActivity;
import god530.com.simpleapp_slide.account.utils.TimeUtils;

/**
 * @deprecated  这个界面不能快速的迭代开发， 所以先弄一个闪屏页面
 */
public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener, Button.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbar.setTitle(TimeUtils.getCurrentMonthYear());
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        initView();

    }

    public void initView() {
//        findViewById(R.id.tabs_details).setOnClickListener(this);
//        findViewById(R.id.tabs_account).setOnClickListener(this);
//        findViewById(R.id.tabs_report).setOnClickListener(this);
//        findViewById(R.id.tabs_information).setOnClickListener(this);
//
//        findViewById(R.id.content_record).setOnClickListener(this);

        this.getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.mainactivity_container, AccountFragment.getInstance()).commit();

    }




    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        switch (id) {
            case R.id.main_navigation_feedback:
                // TODO
                FeedBackActivity.launch(this);
                break;
            case R.id.main_navigation_gesture:
                // TODO
                GestureActivity.launch(this);
                break;
            case R.id.main_navigation_help:
                // TODO
                HelpActivity.launch(this);
                break;
            case R.id.main_navigation_order:
                // TODO
                OrderActivity.lauch(this);
                break;
            case R.id.main_navigation_setting:
                // TODO
                SettingActivity.lauch(this);
                break;
            case R.id.main_navigation_user:
                // TODO
                UserActivity.lauch(this);
                break;
            default:
                break;
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tabs_details:  // 明细
                DetailsActivity.launch(this);
                break;
            case R.id.tabs_account:  // 账户
                AccountActivity.launch(this);
                break;
            case R.id.tabs_report:  // 报表
                ReportActivity.launch(this);
                break;
            case R.id.tabs_information: // 数据
                //TODO
                break;
            case R.id.content_record: // 记一笔
                WriteActivity.lauch(this);
                break;
        }
    }
}
